import instance from '@/assets/js/utils'
/* 注册vux组件 */
import {
  Alert,
  Card,
  Cell,
  CellBox,
  CheckIcon,
  ConfirmPlugin,
  Datetime,
  Grid,
  GridItem,
  Group,
  Loading,
  LoadMore,
  Popup,
  PopupHeader,
  PopupRadio,
  Tab,
  TabItem,
  Toast,
  ToastPlugin,
  TransferDom,
  XCircle,
  XHeader,
  XTextarea,
  XInput
} from 'vux'
/* 注册自定义组件 */
import accordion from '@/components/accordion'
import DeptTree from '@/components/tree/deptTree'
import detailTable from '@/components/table/detailTable'
import SideBar from '@/components/sidebar/sideBar'
import SimpleSearch from '@/components/search/simpleSearch'
import PersonTree from '@/components/tree/personTree'
import PhotoUpload from '@/components/file-upload/photoUpload'
import PictureUpload from '@/components/file-upload/pictureUpload'
// import CheckIcon from '@/components/icon/checkIcon'

/* 引入scroller组件 */
import VueScroller from 'vue-scroller'
/* 引入svgIcon */
import Icon from 'vue-svg-icon/Icon'
import store from '@/store'
/* 引入百度地图 */
import BaiduMap from 'vue-baidu-map'
import Calendar from 'vue-calendar-component'

/* 引入utils方法 */
import {
  getReqUrl,
  downloadFile,
  getTaskParams,
  getRiskParams,
  getUserDetailParams,
  guid,
  pattern,
  toTree,
  toTreeWithSearch,
  signMD5,
  wgs84tobd09,
  gc02tobd09
} from './utils'

let DEV_FLAG = true
let prodUrl = process.env.BASE_URL

export default {
  install: function (Vue, options) {
    if (DEV_FLAG) {
      Vue.prototype.baseUrl = '/'
    } else {
      Vue.prototype.baseUrl = prodUrl
    }
    Vue.prototype.SXDTPM_URL =
      Vue.prototype.baseUrl + 'sxdtpm/servlet/Action.cmd'
    Vue.prototype.COMMON_URL =
      Vue.prototype.baseUrl + 'sxdtpm/servlet/Action.cmd'
    Vue.prototype.LOGIN_URL =
      Vue.prototype.baseUrl + 'sxdtpm/servlet/LoginServlet.cmd'
    Vue.prototype.FORM2SUBSYS_SUPPORT_URL =
      Vue.prototype.baseUrl + 'sxdtpm/servlet/StreamSupportAction.cmd'

    Vue.prototype.$ajax = instance
    Vue.prototype.downloadFile = downloadFile

    Vue.component('card', Card)
    Vue.component('cell', Cell)
    // Vue.component('check-icon', CheckIcon)
    // Vue.component('check-icon', CheckIcon)
    Vue.component('datetime', Datetime)
    Vue.component('grid', Grid)
    Vue.component('grid-item', GridItem)
    Vue.component('cell-box', CellBox)
    Vue.component('group', Group)
    Vue.component('card', Card)
    Vue.component('loading', Loading)
    Vue.component('load-more', LoadMore)
    Vue.component('popup', Popup)
    Vue.component('calendar', Calendar)
    Vue.component('popup-header', PopupHeader)
    Vue.component('popup-radio', PopupRadio)
    Vue.component('tab', Tab)
    Vue.component('tab-item', TabItem)
    Vue.component('toast', Toast)
    Vue.directive('transfer-dom', TransferDom)
    Vue.component('x-circle', XCircle)
    Vue.component('x-header', XHeader)
    Vue.component('x-input', XInput)
    Vue.component('x-textarea', XTextarea)
    Vue.use(ConfirmPlugin)
    Vue.use(ToastPlugin)
    Vue.component('simple-search', SimpleSearch)
    Vue.component('photo-upload', PhotoUpload)
    Vue.component('picture-upload', PictureUpload)
    Vue.component('accordion', accordion)
    Vue.component('person-tree', PersonTree)
    Vue.component('dept-tree', DeptTree)
    Vue.component('detail-table', detailTable)
    Vue.component('side-bar', SideBar)
    Vue.use(VueScroller)
    Vue.component('icon', Icon)
    Vue.component('alert', Alert)
    Vue.use(BaiduMap, {
      // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
      ak: 'yGIpGxyu0RD8YMhs6oem9IlZTLvZvjnI'
    })
    Vue.component('calendar', Calendar)

    Vue.prototype.getReqUrl = getReqUrl // 获取请求加密参数
    Vue.prototype.getTaskParams = getTaskParams // 获取不同服务器表单参数
    Vue.prototype.getRiskParams = getRiskParams
    Vue.prototype.getUserDetailParams = getUserDetailParams
    Vue.prototype.guid = guid // 获取guid
    Vue.prototype.toTree = toTree // 数组转换成树
    Vue.prototype.toTreeWithSearch = toTreeWithSearch // 数组转换成树
    Date.prototype.pattern = pattern
    Vue.prototype.signMD5 = signMD5
    Vue.prototype.wgs84tobd09 = wgs84tobd09
    Vue.prototype.gc02tobd09 = gc02tobd09

    // 强制关闭遮盖层
    Vue.prototype.closeMask = function () {
      let mask = document.querySelector('.vux-popup-mask')
      mask.classList.remove('vux-popup-show')
      setTimeout(() => {
        mask && !/show/.test(mask.className) && (mask.style['zIndex'] = -1)
      }, 400)
      if (store.state.defaultPop) {
        store.commit('CHANGE_DEFAULT_POPUP')
      }
    }

    //   //登出
    //   Vue.prototype.loginOut = function () {
    //     this.$router.push('/')
    //   }

    // 获取用户
    Vue.prototype.getPerson = function (username, type, callback) {
      this.$ajax({
        method: 'post',
        url:
          this.COMMON_URL + '?_method=V_USER_SELECT*getHRUserListSec&type=prj',
        data: {
          MiniQueryFormData:
            '{"RoleId":"","GroupId":"","UserFullName":"' + username + '"}',
          pageIndex: '0',
          pageSize: '1000',
          sortField: 'USER_FULLNAME',
          sortOrder: 'asc'
        }
      })
        .then(res => {
          callback(res)
        })
        .catch(err => {
          console.log(err)
        })
    }

    // 获取token
    //   Vue.prototype.getToken = function (username, password) {
    //     this.$http({
    //       method: 'post',
    //       url: TOKEN_URL + "?username=" + username + "&password=" + password,
    //       data: {}
    //     }).then((res) => {
    //       if (res.data.code == 200) {
    //         window.localStorage.setItem("token", res.data.msg);
    //         this.$store.dispatch('getUserInfo')
    //         this.$store.dispatch('getNews')
    //         this.$store.dispatch('getDept', {
    //           id: 0
    //         })
    //       }
    //     })
    //     .catch((err) => {
    //         console.log(err)
    //     })
    //   }

    // 格式国际标准时间格式为200-mm-dd 放回日期和时间 分钟
    //   Vue.prototype.formatDatee = formatDatee
    //   Vue.prototype.formatDate = formatDate
    // 判断对象为空
    Vue.prototype.isEmptyObject = e => {
      var t
      for (t in e) return !1
      return !0
    }
  }
}
